package xxy.com.yangproject;

import android.Manifest;
import android.os.Bundle;
import android.os.PersistableBundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.work.impl.utils.PreferenceUtils;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;

import xxy.com.yangproject.global.Constant;

public class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        NetworkUtils.registerNetworkStatusChangedListener(networkStatusChangedListener);
    }

    @Override
    protected void onStart() {
        super.onStart();
        ToastUtils.showShort(NetworkUtils.isRegisteredNetworkStatusChangedListener(networkStatusChangedListener) ? "已注册网络监听" : "未注册网络监听");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        NetworkUtils.unregisterNetworkStatusChangedListener(networkStatusChangedListener);
    }

  private NetworkUtils.OnNetworkStatusChangedListener networkStatusChangedListener =   new NetworkUtils.OnNetworkStatusChangedListener() {
        @Override
        public void onDisconnected() {
            ToastUtils.showShort( "网络断开");
        }

        @Override
        public void onConnected(NetworkUtils.NetworkType networkType) {
            switch (networkType){
                case NETWORK_WIFI:
                    ToastUtils.showShort( "已连接无线网");
                    break;
                case NETWORK_5G:
                    ToastUtils.showShort( "已连接5G");
                    break;
                case NETWORK_4G:
                    ToastUtils.showShort( "已连接4G");
                    break;
                case NETWORK_3G:
                    ToastUtils.showShort( "已连接3G");
                    break;
                case NETWORK_2G:
                    ToastUtils.showShort( "已连接2G");
                    break;
                case NETWORK_UNKNOWN:
                    ToastUtils.showShort( "未知连接UNKNOWN");
                    break;
                case NETWORK_NO:
                    ToastUtils.showShort( "无连接");
                    break;
                default:
                    break;
            }
        }
    };
}
